/**
 * Interactivity of data_table
 */
function showHide(parent) {
    var fade = document.getElementById('fade');
    if (fade == null) {
        fade = document.createElement('div');
        fade.style.zIndex = 800;
        fade.style.backgroundColor = 'white';
        fade.style.position = 'fixed';
        fade.style.left = 0;
        fade.style.top = 0;
        fade.style.right = 0;
        fade.style.bottom = 0;
        fade.style.display = 'none';
        fade.id = 'fade';
        fade.style.opacity = '0.95';
        document.body.appendChild(fade);
    }
    
    if (parent.style.position != 'absolute') {
        parent.style.position = 'absolute';
        parent.style.left = '0';
        parent.style.zIndex = 1000;
        parent.style.width = '100%';
        fade.style.display = 'block';
        fade.onclick = function() {
            parent.style.position = 'inherit';
            parent.style.width = 'inherit';
            fade.style.display = 'none';
        }
    } else {
        parent.style.position = 'inherit';
        parent.style.width = 'inherit';
        fade.style.display = 'none';
    }
}

/**
 * Titles for cells
 */
$(document).ready (function() {
    $('.time').attr('title', 'Sugaištas laikas');
    $('.addministrated').attr('title', 'Suadministruotų paraiškų kiekis');
    $('.previous').attr('title', 'Likę paraiškų nuo anksčiau');
    $('.received').attr('title', 'Gautų paraiškų kiekis');
});

/**
 * Auto fillers
 */
function fill_foresee_quantities(container) {
    var received = null;
    var administrated = null;
    var default_value = 100;
    container = '#' + container + ' .measure_quantities';
    $.each($(container).find("input"), function(i, input) {
        if (input.value) {
            if (input.name.indexOf('received') > -1) {
                received = input.value;
            } else {
                administrated = input.value;
            }
        } else if (!input.value) {
            if (input.name.indexOf('received') > -1 && received) {
                input.value = received;
            } else if (input.name.indexOf('administrated') > -1 && administrated) {
                input.value = administrated;
            } else if (received) {
                input.value = received;
            } else if (administrated) {
                input.value = administrated;
            } else {
                input.value = default_value;
            }
        }
    });
}